package com.cardbaobao.cardbabyclient.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.cardbaobao.cardbabyclient.R;
import com.cardbaobao.cardbabyclient.api.Api;
import com.cardbaobao.cardbabyclient.buried.Google;
import com.cardbaobao.cardbabyclient.buried.Self;
import com.cardbaobao.cardbabyclient.buried.SelfUtils;
import com.cardbaobao.cardbabyclient.ui.activity.base.BaseActivity;
import com.cardbaobao.cardbabyclient.ui.activity.web.EventWebViewActivity;
import com.cardbaobao.cardbabyclient.ui.adapter.BankScreenAdapter;
import com.cardbaobao.cardbabyclient.ui.adapter.SpeedCardRcAdapter;
import com.cardbaobao.cardbabyclient.ui.adapter.ThemeOrRankScreenAdapter;
import com.cardbaobao.cardbabyclient.base.Constant;
import com.cardbaobao.cardbabyclient.controller.CommonJumpController;
import com.cardbaobao.cardbabyclient.model.Banner;
import com.cardbaobao.cardbabyclient.model.SpeedCard;
import com.cardbaobao.cardbabyclient.model.SpeedCardTag;
import com.cardbaobao.cardbabyclient.model.result.BannerResult;
import com.cardbaobao.cardbabyclient.model.result.SpeedCardResult;
import com.cardbaobao.cardbabyclient.model.result.SpeedCardTagResult;
import com.cardbaobao.cardbabyclient.utils.ApplicationHelper;
import com.cardbaobao.cardbabyclient.utils.DensityUtil;
import com.cardbaobao.cardbabyclient.buried.GoogleAnalyticsUtil;
import com.cardbaobao.cardbabyclient.utils.ImageLoaderUtil;
import com.cardbaobao.cardbabyclient.utils.JsonUtil;
import com.cardbaobao.cardbabyclient.utils.LocationUtil;
import com.cardbaobao.cardbabyclient.utils.ScreenUtil;
import com.cardbaobao.cardbabyclient.utils.ToastUtil;
import com.cardbaobao.cardbabyclient.utils.URLUtil;
import com.cardbaobao.cardbabyclient.utils.UmengEventUtils;
import com.cardbaobao.cardbabyclient.ui.pop.CustomPopWin;
import com.cardbaobao.cardbabyclient.widget.RecyclerViewWithFooter.OnLoadMoreListener;
import com.cardbaobao.cardbabyclient.widget.RecyclerViewWithFooter.RecyclerViewWithFooter;
import com.cardbaobao.cardbabyclient.widget.TitleBar;
import com.cardbaobao.cardbabyclient.widget.divider.VerticalItemDecoration;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.stx.xhb.xbanner.XBanner;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import rx.Observable;
import rx.Subscriber;

/**
 * Description: 极速办卡
 * Created by FHW
 * on 2017/6/19
 */
public class SpeedCardActivity extends BaseActivity implements View.OnClickListener {

    public static int RESULT_CODE = 1;
    //银行
    public static final String BANK_ID_I = "companyId";
    public static final String BANK_NAME_S = "bankName";
    //主题
    public static final String THEME_CODE_S = "theme_code";
    public static final String THEME_NAME_S = "name_theme";
    //等级

    @BindView(R.id.tw_toolbar)
    TitleBar tw_toolbar;

    @BindView(R.id.main_appbar)
    AppBarLayout main_appbar;
    @BindView(R.id.xb_banner)
    XBanner xb_banner;
    @BindView(R.id.ll_tab_title)
    LinearLayout ll_tab_title;
    @BindView(R.id.ll_type_bank)
    LinearLayout ll_type_bank;

    @BindView(R.id.ll_type_theme)
    LinearLayout ll_type_theme;
    @BindView(R.id.ll_type_grade)
    LinearLayout ll_type_grade;
    @BindView(R.id.tv_type_bank)
    TextView tv_type_bank;

    @BindView(R.id.tv_type_theme)
    TextView tv_type_theme;
    @BindView(R.id.tv_type_grade)
    TextView tv_type_grade;
    @BindView(R.id.iv_type_bank)
    ImageView iv_type_bank;
    @BindView(R.id.iv_type_theme)
    ImageView iv_type_theme;
    @BindView(R.id.iv_type_grade)
    ImageView iv_type_grade;

    @BindView(R.id.rv_speed_card)
    RecyclerViewWithFooter rv_speed_card;
    @BindView(R.id.srLayout)
    SmartRefreshLayout srLayout;

    private SpeedCardRcAdapter mAdapter;

    private int mType = 0;//0-银行 1-主题 2-等级

    private CustomPopWin popwin;

    private boolean isLoading = false;

    private List<Banner.CarouselFigureListBean> bannerList;

    private List<SpeedCard.SpeedCardListBean> speedCardListBeanList;

    private int mPage = 1;

    private int company_id = -1;//银行id
    private String theme_code = "";//主题code
    private String rank_code = "";//等级code

    private BankScreenAdapter bankScreenAdapter;
    private int bankLastPosi = 0;//记录上次的筛选条件

    private ThemeOrRankScreenAdapter themeScreenAdapter;
    private int themeLastPosi = 0;//记录上次的筛选条件

    private ThemeOrRankScreenAdapter rankScreenAdapter;
    private int rankLastPosi = 0;//记录上次的筛选条件

    private String name_bank = "全部银行";//银行
    private String name_theme = "全部主题";//主题
    private String name_rank = "全部等级";//等级

    private List<SpeedCardTag.BankListBean> bank_list;
    private List<SpeedCardTag.ThemeListBean> theme_list;
    private List<SpeedCardTag.ThemeListBean> rank_list;

    @BindView(R.id.ll_no_data)
    LinearLayout ll_no_data;

    @Override
    protected void onResume() {
        super.onResume();
        GoogleAnalyticsUtil.setScreenName(Google.SPEED_CREDIT);
        UmengEventUtils.pageEvent(mContext,getString(R.string.event_0x049));
    }

    @Override
    protected void initView(Bundle savedInstanceState) {

        mCurrentPageId= Self.Page.app_speed_credit_card_page;

        Intent intent = getIntent();
        company_id = intent.getIntExtra(BANK_ID_I, company_id);
        name_bank = intent.getStringExtra(BANK_NAME_S);

        if (TextUtils.isEmpty(name_bank)) {
            name_bank = "全部银行";
        }

        name_theme = intent.getStringExtra(THEME_NAME_S);
        if (TextUtils.isEmpty(name_theme)) {
            name_theme = "全部主题";
        }
        theme_code = intent.getStringExtra(THEME_CODE_S);
        if (TextUtils.isEmpty(theme_code)) {
            theme_code = "";
        }

        bannerList = new ArrayList<>();
        speedCardListBeanList = new ArrayList<>();

        bank_list = new ArrayList<>();
        theme_list = new ArrayList<>();
        rank_list = new ArrayList<>();

        ll_type_bank.setOnClickListener(this);
        ll_type_theme.setOnClickListener(this);
        ll_type_grade.setOnClickListener(this);

        getBannerPic();

        srLayout.setEnableLoadmore(false);
        main_appbar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
            @Override
            public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
                srLayout.setEnableRefresh(verticalOffset==0);
            }
        });
        setRvData();
        getSpeedCardData(true);

        getCardTabData();

        tw_toolbar.setLeftViewOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        rv_speed_card.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore() {
                getSpeedCardData(false);
            }
        });
        srLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshlayout) {
                onRefreshRv();
            }
        });
    }

    private void onRefreshRv() {
        mPage = 1;
        rv_speed_card.setEmpty();
        getSpeedCardData(true);
    }

    /**
     * 极速办卡标签页
     */
    private void getCardTabData() {
        Observable<String> observable= Api.speedCardLabel();
        observable.subscribe(new Subscriber<String>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                ToastUtil.showToast(ApplicationHelper.
                        getApplicationContext().
                        getString(R.string.string_request_server_fail));
            }

            @Override
            public void onNext(String s) {
                SpeedCardTagResult speedCardTagResult = JsonUtil.json2Object(s, SpeedCardTagResult.class);
                if (speedCardTagResult.getCode() == Constant.SUC_CODE) {
                    if (speedCardTagResult.getData() != null) {
                        if (speedCardTagResult.getData().getBank_list() != null) {
                            bank_list.addAll(speedCardTagResult.getData().getBank_list());
                            bank_list.add(0, new SpeedCardTag.BankListBean("全部银行", true));
                        }
                        if (speedCardTagResult.getData().getTheme_list() != null) {
                            theme_list.addAll(speedCardTagResult.getData().getTheme_list());
                            theme_list.add(0, new SpeedCardTag.ThemeListBean("全部主题", true));
                        }
                        if (speedCardTagResult.getData().getRank_list() != null) {
                            rank_list.addAll(speedCardTagResult.getData().getRank_list());
                            rank_list.add(0, new SpeedCardTag.ThemeListBean("全部等级", true));
                        }
                    }
                } else {
                    ToastUtil.showToast(speedCardTagResult.getMsg());
                }
            }
        });
    }

    /**
     * 获取极速办卡数据
     */
    private void getSpeedCardData(final boolean isClean) {
        Map<String,Object> params = new HashMap<>();
        params.put("page_number", mPage);
        if (company_id != -1) {
            params.put("company_id", company_id);
        }
        if (!TextUtils.isEmpty(theme_code)) {
            params.put("theme_code", theme_code);
        }
        if (!TextUtils.isEmpty(rank_code)) {
            params.put("rank_code", rank_code);
        }
        if (!TextUtils.isEmpty(LocationUtil.getCityID())) {
            params.put("city_id", LocationUtil.getCityID());
        }
        if (isClean){
            showProgressDialog(true);
        }
        Observable<String> observable=Api.speedCardData(params);
        observable.subscribe(new Subscriber<String>() {
            @Override
            public void onCompleted() {
                dismissProgressDialog();
                srLayout.finishRefresh();
                tv_type_bank.setText(name_bank);
                tv_type_theme.setText(name_theme);
                tv_type_grade.setText(name_rank);
            }

            @Override
            public void onError(Throwable e) {
                dismissProgressDialog();
                ToastUtil.showToast(ApplicationHelper.
                        getApplicationContext().
                        getString(R.string.string_request_server_fail));
            }

            @Override
            public void onNext(String s) {
                SpeedCardResult speedCardResult = JsonUtil.json2Object(s, SpeedCardResult.class);
                if (speedCardResult.getCode() == Constant.SUC_CODE) {
                    if (speedCardResult.getData() != null) {

                        if (isClean) {
                            speedCardListBeanList.clear();

                            if (speedCardResult.getData().getSpeed_card_list() != null && speedCardResult.getData().getSpeed_card_list().size() > 0) {
                                srLayout.setVisibility(View.VISIBLE);
                                ll_no_data.setVisibility(View.GONE);
                            } else {
                                srLayout.setVisibility(View.GONE);
                                ll_no_data.setVisibility(View.VISIBLE);
                            }
                        }

                        speedCardListBeanList.addAll(speedCardResult.getData().getSpeed_card_list());
                        //分页
                        if (speedCardResult.getData().getSpeed_card_list().size() > 10) {
                            mPage++;
                            rv_speed_card.setLoading();
                        } else {
                            rv_speed_card.setEnd("没有更多了");
                        }

                        mAdapter.setData(speedCardListBeanList);
                    }
                } else {
                    ToastUtil.showToast(speedCardResult.getMsg());
                }
            }
        });
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_speed_card;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_type_bank:
                mType = 0;
                showTypeView();
                showPopView(v);
                break;
            case R.id.ll_type_theme:
                mType = 1;
                showTypeView();
                showPopView(v);
                break;
            case R.id.ll_type_grade:
                mType = 2;
                showTypeView();
                showPopView(v);
                break;
        }
    }

    private void showPopView(View view) {

        View popView = LayoutInflater.from(this).inflate(R.layout.pop_card_screen, null, false);
        GridView gv_bank = (GridView) popView.findViewById(R.id.gv_bank);
        GridView gv_theme = (GridView) popView.findViewById(R.id.gv_theme);
        GridView gv_grade = (GridView) popView.findViewById(R.id.gv_grade);

        TextView tv_reset = (TextView) popView.findViewById(R.id.tv_reset);
        TextView tv_ok = (TextView) popView.findViewById(R.id.tv_ok);

        LinearLayout ll_gview = (LinearLayout) popView.findViewById(R.id.ll_gview);
        LinearLayout ll_content = (LinearLayout) popView.findViewById(R.id.ll_content);

        View v_dimess = popView.findViewById(R.id.v_dimess);

        int[] location = new int[2];
        ll_tab_title.getLocationOnScreen(location);
        int w = View.MeasureSpec.makeMeasureSpec(0,
                View.MeasureSpec.UNSPECIFIED);
        int h = View.MeasureSpec.makeMeasureSpec(0,
                View.MeasureSpec.UNSPECIFIED);
        ll_gview.measure(w, h);
        ll_tab_title.measure(w, h);
        int minH = ScreenUtil.getScreenHeight(this) - location[1] - ll_tab_title.getHeight();
        if (minH < ll_gview.getMeasuredHeight()) {//适配小屏幕
            ViewGroup.LayoutParams layoutParams = ll_content.getLayoutParams();
            layoutParams.height = minH - ll_tab_title.getHeight();
            ll_content.setLayoutParams(layoutParams);
        }

        gv_bank.setVisibility(View.GONE);
        gv_theme.setVisibility(View.GONE);
        gv_grade.setVisibility(View.GONE);

        if (popwin == null) {
            popwin = new CustomPopWin(this, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f);
        }
        switch (mType) {
            case 0:
                gv_bank.setVisibility(View.VISIBLE);
                setBankAdapter(gv_bank);
                break;
            case 1:
                gv_theme.setVisibility(View.VISIBLE);
                setThemeAdapter(gv_theme);
                break;
            case 2:
                gv_grade.setVisibility(View.VISIBLE);
                setRankAdapter(gv_grade);
                break;
        }
        popwin.setFocusable(false);
        popwin.setContentView(popView);
        popwin.showAsDropDown(view, 0, 0);

        popwin.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                setTypeNormal();
            }
        });

        v_dimess.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popwin.dismiss();
            }
        });

        tv_reset.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (mType) {
                    case 0:
                        for (int i = 0; i < bank_list.size(); i++) {
                            bank_list.get(i).setChoose(false);
                            if (i == 0) {
                                bank_list.get(i).setChoose(true);
                            }
                        }

                        bankScreenAdapter.notifyDataSetChanged();
                        break;
                    case 1:
                        for (int i = 0; i < theme_list.size(); i++) {
                            theme_list.get(i).setChoose(false);
                            if (i == 0) {
                                theme_list.get(i).setChoose(true);
                            }
                        }
                        themeScreenAdapter.notifyDataSetChanged();
                        break;
                    case 2:
                        for (int i = 0; i < rank_list.size(); i++) {
                            rank_list.get(i).setChoose(false);
                            if (i == 0) {
                                rank_list.get(i).setChoose(true);
                            }
                        }
                        rankScreenAdapter.notifyDataSetChanged();
                        break;
                }
            }
        });
        tv_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (mType) {
                    case 0:
                        for (int i = 0; i < bank_list.size(); i++) {
                            if (bank_list.get(i).isChoose()) {
                                bankLastPosi = i;
                                company_id = bank_list.get(i).getID();
                                name_bank = bank_list.get(i).getNameShort();
                            }
                        }
                        SelfUtils.buriedClickData(Self.Action.app_click_speed_card_choose_bank,
                                Self.Action.app_click_speed_card_choose_bank_des,
                                mEnterPageTime,
                                mCurrentPageId,
                                mPrePageId);
                        break;
                    case 1:
                        for (int i = 0; i < theme_list.size(); i++) {
                            if (theme_list.get(i).isChoose()) {
                                themeLastPosi = i;
                                theme_code = theme_list.get(i).getCode();
                                name_theme = theme_list.get(i).getName();
                            }
                        }
                        SelfUtils.buriedClickData(Self.Action.app_click_speed_card_choose_feature,
                                Self.Action.app_click_speed_card_choose_feature_des,
                                mEnterPageTime,
                                mCurrentPageId,
                                mPrePageId);
                        break;
                    case 2:
                        for (int i = 0; i < rank_list.size(); i++) {
                            if (rank_list.get(i).isChoose()) {
                                rankLastPosi = i;
                                rank_code = rank_list.get(i).getCode();
                                name_rank = rank_list.get(i).getName();
                            }
                        }
                        SelfUtils.buriedClickData(Self.Action.app_click_speed_card_choose_level,
                                Self.Action.app_click_speed_card_choose_level_des,
                                mEnterPageTime,
                                mCurrentPageId,
                                mPrePageId);
                        break;
                }
                onRefreshRv();
                popwin.dismiss();
            }
        });

        gv_bank.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                for (int i = 0; i < bank_list.size(); i++) {
                    bank_list.get(i).setChoose(false);
                    if (position == i) {
                        bank_list.get(i).setChoose(true);
                    }
                }
                bankScreenAdapter.notifyDataSetChanged();
            }
        });
        gv_theme.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                for (int i = 0; i < theme_list.size(); i++) {
                    theme_list.get(i).setChoose(false);
                    if (position == i) {
                        theme_list.get(i).setChoose(true);
                    }
                }
                themeScreenAdapter.notifyDataSetChanged();
            }
        });
        gv_grade.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                for (int i = 0; i < rank_list.size(); i++) {
                    rank_list.get(i).setChoose(false);
                    if (position == i) {
                        rank_list.get(i).setChoose(true);
                    }
                }
                rankScreenAdapter.notifyDataSetChanged();
            }
        });


    }

    private void setBankAdapter(GridView gv) {
        for (int i = 0; i < bank_list.size(); i++) {
            bank_list.get(i).setChoose(false);
            if (bankLastPosi == i) {
                bank_list.get(i).setChoose(true);
            }
        }
        bankScreenAdapter = new BankScreenAdapter(mContext, bank_list, R.layout.item_card_screen_gv);
        gv.setAdapter(bankScreenAdapter);
    }

    private void setThemeAdapter(GridView gv) {
        for (int i = 0; i < theme_list.size(); i++) {
            theme_list.get(i).setChoose(false);
            if (themeLastPosi == i) {
                theme_list.get(i).setChoose(true);
            }
        }
        themeScreenAdapter = new ThemeOrRankScreenAdapter(mContext, theme_list, R.layout.item_card_screen_gv);
        gv.setAdapter(themeScreenAdapter);
    }

    private void setRankAdapter(GridView gv) {
        for (int i = 0; i < rank_list.size(); i++) {
            rank_list.get(i).setChoose(false);
            if (rankLastPosi == i) {
                rank_list.get(i).setChoose(true);
            }
        }
        rankScreenAdapter = new ThemeOrRankScreenAdapter(mContext, rank_list, R.layout.item_card_screen_gv);
        gv.setAdapter(rankScreenAdapter);
    }

    private void showTypeView() {
        setTypeNormal();
        switch (mType) {
            case 0:
                tv_type_bank.setTextColor(getResources().getColor(R.color.color_FF9E27));
                iv_type_bank.setBackgroundResource(R.mipmap.icon_arrow_up_s);
                break;
            case 1:
                tv_type_theme.setTextColor(getResources().getColor(R.color.color_FF9E27));
                iv_type_theme.setBackgroundResource(R.mipmap.icon_arrow_up_s);
                break;
            case 2:
                tv_type_grade.setTextColor(getResources().getColor(R.color.color_FF9E27));
                iv_type_grade.setBackgroundResource(R.mipmap.icon_arrow_up_s);
                break;
        }
    }

    private void setTypeNormal() {
        tv_type_bank.setTextColor(getResources().getColor(R.color.color_222222));
        tv_type_theme.setTextColor(getResources().getColor(R.color.color_222222));
        tv_type_grade.setTextColor(getResources().getColor(R.color.color_222222));
        iv_type_bank.setBackgroundResource(R.mipmap.icon_arrow_down_n);
        iv_type_theme.setBackgroundResource(R.mipmap.icon_arrow_down_n);
        iv_type_grade.setBackgroundResource(R.mipmap.icon_arrow_down_n);
    }


    private void setRvData() {
        mAdapter = new SpeedCardRcAdapter(this);
        mAdapter.setBuriedInfo(mEnterPageTime,mCurrentPageId,mPrePageId);
        rv_speed_card.setLayoutManager(new LinearLayoutManager(this));
        rv_speed_card.addItemDecoration(
                new VerticalItemDecoration(0x00000000, DensityUtil.dp2px(mApplicationContext, 16)));
        rv_speed_card.setAdapter(mAdapter);
    }

    private void setBannerData() {
        //添加广告数据
        xb_banner.setData(bannerList, null);//第二个参数为提示文字资源集合
        xb_banner.setmAutoPalyTime(Constant.BANNER_INTERVAL_TIME);
        xb_banner.setmAdapter(new XBanner.XBannerAdapter() {
            @Override
            public void loadBanner(XBanner banner, Object model, View view, int position) {
                ImageLoaderUtil.displayImage(URLUtil.CBB_IMG_URL + bannerList.get(position).getImage(), (ImageView) view);
            }
        });
        xb_banner.setOnItemClickListener(new XBanner.OnItemClickListener() {
            @Override
            public void onItemClick(XBanner banner, int position) {
                SelfUtils.buriedClickData(Self.Action.app_click_speed_card_top_banner,
                        Self.Action.app_click_speed_card_top_banner_des,
                        mEnterPageTime,
                        mCurrentPageId,
                        null);
                CommonJumpController controller = new CommonJumpController(mContext);
                Banner.CarouselFigureListBean bean = bannerList.get(position);
                Map<String, Object> map = new HashMap<>();
                map.put(CommonJumpController.FROM_PAGE, getString(R.string.text_speed_credit));
                map.put(EventWebViewActivity.WEB_TYPE_I, 4);
                controller.bannerJump(bean, map);
            }
        });

    }

    /**
     * 获取轮播图
     */
    private void getBannerPic() {
        if (isLoading) {
            return;
        }
        isLoading = true;
        Observable<String> observable=Api.getBannerData(Constant.GLB0313);
        observable.subscribe(new Subscriber<String>() {
            @Override
            public void onCompleted() {
                isLoading=false;
            }

            @Override
            public void onError(Throwable e) {
                isLoading=false;
                ToastUtil.showToast(ApplicationHelper.
                        getApplicationContext().
                        getString(R.string.string_request_server_fail));
            }

            @Override
            public void onNext(String s) {
                BannerResult bannerResult = JsonUtil.json2Object(s, BannerResult.class);
                if (bannerResult.getCode() == Constant.SUC_CODE) {
                    if (bannerResult.getData() != null) {
                        bannerList.addAll(bannerResult.getData().getCarousel_figure_list());
                        if (bannerList.size() > 0) {
                            setBannerData();
                        } else {
                            xb_banner.setVisibility(View.GONE);
                        }
                    }
                } else {
                    ToastUtil.showToast(bannerResult.getMsg());
                }
            }
        });
    }

    @Override
    public void finish() {
        setResult(RESULT_CODE);
        super.finish();
    }
}
